//
//  IAPHelper.h
//  InAppRage
//
//  Created by Ray Wenderlich on 2/28/11.
//  Copyright 2011 Ray Wenderlich. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "StoreKit/StoreKit.h"
#define kProductsLoadedNotification                 @"ProductsLoaded"
#define kProductPurchasedNotification               @"ProductPurchased"
#define kProductPurchaseFailedNotification          @"ProductPurchaseFailed"
#define kGetProductIdentifierFailedNotification     @"GetProductIdentifierFailed"
#define kTransactionStatePurchasing                 @"TransactionStatePurchasing"
#define kSucceedGetProductIdentifierNotification    @"SucceedGetProductIdentifier"

#define kProductsRequestFailNotification            @"ProductsRequestFail"

#define kSucceedRechargeNotification                @"SucceedRecharge"
#define kFailedRechargeNotification                 @"FailedRecharge"

#define  kNotificationAppstoreRechargeFininsh       @"kNotificationAppstoreRechargeFininsh"         //appstore充值

//上传服务器处理
#define  kNotificationAppstoreRechargeFinishedUpload       @"kNotificationAppstoreRechargeFinishedUpload"


@protocol IAPHelperProtocal <NSObject>

@required
- (void)getProductsWithResultSuccess:(BOOL)aFlag error:(NSError *)aError;

@end

@interface IAPHelper : NSObject<SKProductsRequestDelegate,SKPaymentTransactionObserver,NSURLConnectionDelegate>
{
    NSMutableArray  *_products;
    SKProductsRequest *_request;

  
    NSMutableArray  *_productIDStack;
    BOOL      _bGettingProducts;
    NSURLConnection *_rechargeTestConnection;

}

@property (readwrite, retain) NSMutableSet *productIdentifiers;
@property (readwrite, retain) NSMutableSet *packageProductIdentifiers;
@property (nonatomic,retain) NSMutableArray *products;
@property (retain) SKProductsRequest *request;
@property (assign, readwrite) id<IAPHelperProtocal> iapDelegate;
@property (nonatomic,retain)  NSMutableDictionary *productIDwithMoney;
@property (nonatomic,strong)  NSArray *appProductIDArray;//产品id数组
@property (nonatomic,strong)  NSString      *payOrderNo;//订单编号

- (void)requestProducts;
- (void)buyProduct:(SKProduct *)product;

/**
 *  未上传成功的服务器处理
 */
//- (void)uploadHandler;

+ (IAPHelper *)sharedInstance;
@end
